package com.project.controller;

import com.project.dto.MaterialCategoryDTO;
import com.project.dto.MaterialCategoryPageQueryDTO;
import com.project.result.PageResult;
import com.project.result.Result;
import com.project.service.MaterialCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/material-categories")

public class MaterialCategoryController {
    @Autowired
    private MaterialCategoryService materialCategoryService;

    /**
     * 新增材料分类
     */
    @PostMapping
    public Result create(@RequestBody MaterialCategoryDTO dto) {
        materialCategoryService.createCategory(dto);
        return Result.success();
    }

    /**
     * 修改材料分类
     */
    @PutMapping
    public Result update(@RequestBody MaterialCategoryDTO dto) {
        materialCategoryService.updateCategory(dto);
        return Result.success();
    }

    /**
     * 状态选择
     */
    @PutMapping("/status/{status}")
    public Result updateStatus(@PathVariable("status") Integer status,Integer id) {
        materialCategoryService.updateCategoryStatus(status,id);
        return Result.success();
    }


    /**
     * 删除材料分类
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        materialCategoryService.deleteCategory(id);
        return Result.success();
    }

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public Result<PageResult> page(MaterialCategoryPageQueryDTO queryDTO) {

       PageResult page = materialCategoryService.pageQuery(queryDTO);
        return Result.success(page);

    }


}